﻿Imports System.Media

Public Class Form1

    Private Property goingVariable As Integer
    Private Property isRunning As Integer
    Private Property userSoundSet As Boolean
    Private Property userSound As SystemSound
    Private Property newInterval As Integer
    Private Property isPlaying As Boolean
    Private Property warningLength As Integer

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load


    End Sub


    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        isRunning = 1
        isPlaying = False


        'Need to check to see if a different sound has been set
        Dim userSoundSet As Boolean
        Dim userSound As String
        Dim newInterval As Integer

        userSoundSet = False
        If My.Settings.Sound = "" Then
            userSoundSet = False
        Else
            userSound = My.Settings.Sound
            'Now work out how long this sound is




        End If
        newInterval = My.Settings.CheckInteval
        frequencySetting.Text = newInterval / 1000

        'Need to check the StartWithWin setting and set the button text
        If My.Settings.StartWithWin = False Then
            btnAutoStart.Text = "Not starting with Windows, click to enable"
        ElseIf My.Settings.StartWithWin = True Then
            btnAutoStart.Text = "Starting with Windows, click to disable"
        End If



    End Sub

    'End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        If isRunning = 1 Then
            '  MsgBox("Ok Let's stop")
            isRunning = 0
            Button1.Text = "Enable"
        ElseIf isRunning = 0 Then
            ' MsgBox("Let's go")
            isRunning = 1
            Button1.Text = "Disable"
        End If


    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
        MsgBox("Ok, let's stop now")
        isRunning = 0


    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If isRunning = 1 Then




            If My.Computer.Keyboard.CapsLock = True Then

                My.Computer.Audio.PlaySystemSound(SystemSounds.Exclamation)
                NotifyIcon1.Icon = My.Resources.CapsLockOn
                Me.Icon = My.Resources.CapsLockOn
                Label3.Text = "ON!"

            Else
                Label3.Text = "Off"
                NotifyIcon1.Icon = My.Resources.CapsLockOff
                Me.Icon = My.Resources.CapsLockOff



            End If

        End If

    End Sub

    

    Private Sub Label1_Click(sender As System.Object, e As System.EventArgs) Handles Label1.Click

    End Sub


    Private Sub LinkLabel1_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        System.Diagnostics.Process.Start("http://www.computeractive.co.uk")
    End Sub

    Private Sub freqSec_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)

    End Sub

    Private Sub Label5_Click(sender As System.Object, e As System.EventArgs) Handles Label5.Click

    End Sub

    Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'convert frequencySetting to integer

        newInterval = CInt(frequencySetting.Text)

        'Set Tim
        Timer1.Interval = newInterval * 1000
        My.Settings.CheckInteval = newInterval * 1000
        My.Settings.Save()

    End Sub

    
    Private Sub btnAutoStart_Click(sender As System.Object, e As System.EventArgs) Handles btnAutoStart.Click
        'Program starts by default not starting with Windows
        'BUT will need to check anyway
        If My.Settings.StartWithWin = False Then
            'Execute code to adjust registry
            MsgBox(Application.ProductName)
            MsgBox(Application.ExecutablePath)

            My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)

            'Change button Label to Starting with Windows, click to disable
            btnAutoStart.Text = "Starting with Windows, click to disable"
            'Change My.Settings.StartWithWin
            My.Settings.StartWithWin = True
            'Save Setting
            My.Settings.Save()
        ElseIf My.Settings.StartWithWin = True Then
            'Execute code to adjust registry to remove key

            'from stackoverflow
            My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)



            'Change button Label to Not starting with Windows, click to enable
            btnAutoStart.Text = "Not starting with Windows, click to enable"
            'Change My.Settings.StartWithWin
            My.Settings.StartWithWin = False
            'Save Setting
            My.Settings.Save()

        End If
    End Sub

    


End Class
